From a087da79f036e88e42397530cb906ce3ab40d41e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pablo=20Ari=C3=B1o=20Mu=C3=B1oz?= Date: Tue, 25 Feb 2025 15:43:29 +0100 Subject: [PATCH] Added an option to customize the server poll interval in the Advanced Settings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Pablo Ariño Muñoz --- src/gui/generalsettings.cpp | 40 ++++++++++++++++++++++++++++++++- src/gui/generalsettings.h | 2 ++ src/gui/generalsettings.ui | 44 +++++++++++++++++++++++++++++++++++++ src/libsync/configfile.cpp | 21 ++++++++++++++++++ src/libsync/configfile.h | 2 ++ 5 files changed, 108 insertions(+), 1 deletion(-) diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index d4a0aeaa4..cf0794a15 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -50,6 +50,7 @@ #include #include +#include namespace { struct ZipEntry { @@ -187,6 +188,8 @@ GeneralSettings::GeneralSettings(QWidget *parent) { _ui->setupUi(this); + _ui->labelInterval->setOpenExternalLinks(true); + connect(_ui->serverNotificationsCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotToggleOptionalServerNotifications); _ui->serverNotificationsCheckBox->setToolTip(tr("Server notifications that require attention.")); @@ -240,7 +243,8 @@ GeneralSettings::GeneralSettings(QWidget *parent) connect(_ui->stopExistingFolderNowBigSyncCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings); connect(_ui->newExternalStorage, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings); connect(_ui->moveFilesToTrashCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::saveMiscSettings); - + connect(_ui->remotePollIntervalSpinBox, static_cast(&QSpinBox::valueChanged), this, &GeneralSettings::slotRemotePollIntervalChanged); + connect(_ui->remotePollIntervalCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotRemotePollIntervalCheckBoxToggled); #ifndef WITH_CRASHREPORTER _ui->crashreporterCheckBox->setVisible(false); #endif @@ -321,6 +325,13 @@ void GeneralSettings::loadMiscSettings() _ui->stopExistingFolderNowBigSyncCheckBox->setChecked(_ui->existingFolderLimitCheckBox->isChecked() && cfgFile.stopSyncingExistingFoldersOverLimit()); _ui->newExternalStorage->setChecked(cfgFile.confirmExternalStorage()); _ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons()); + + + bool hasCustomInterval = cfgFile.hasRemotePollInterval(); + _ui->remotePollIntervalCheckBox->setChecked(hasCustomInterval); + auto interval = cfgFile.remotePollInterval(); + _ui->remotePollIntervalSpinBox->setValue(static_cast(interval.count() / 1000)); + _ui->remotePollIntervalSpinBox->setEnabled(hasCustomInterval); } #if defined(BUILD_UPDATER) @@ -639,4 +650,31 @@ void GeneralSettings::customizeStyle() #endif } +void GeneralSettings::slotRemotePollIntervalCheckBoxToggled(bool checked) { + _ui->remotePollIntervalSpinBox->setEnabled(checked); // Enable/disable the spin box + + ConfigFile cfgFile; + + if (checked) { + slotRemotePollIntervalChanged(_ui->remotePollIntervalSpinBox->value()); + } else { + // Reset to default interval when unchecked + cfgFile.resetRemotePollInterval(); + + // Update the spinbox with the default value + auto interval = cfgFile.remotePollInterval(); + _ui->remotePollIntervalSpinBox->setValue(static_cast(interval.count() / 1000)); + } +} + +void GeneralSettings::slotRemotePollIntervalChanged(int seconds) { + if (_currentlyLoading) return; + + if (_ui->remotePollIntervalCheckBox->isChecked()) { + ConfigFile cfgFile; + std::chrono::milliseconds interval(seconds * 1000); + cfgFile.setRemotePollInterval(interval); + } +} + } // namespace OCC diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index 83067799a..30d02cdf3 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -59,6 +59,8 @@ private slots: void slotCreateDebugArchive(); void loadMiscSettings(); void slotShowLegalNotice(); + void slotRemotePollIntervalChanged(int seconds); + void slotRemotePollIntervalCheckBoxToggled(bool checked); #if defined(BUILD_UPDATER) void slotUpdateInfo(); void slotUpdateChannelChanged(); diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index 65eb6256c..c48948551 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -186,6 +186,50 @@ + + + + + + Server poll interval + + + + + + + 30 + + + 3600 + + + 1 + + + + + + + seconds (if Client Push is unavailable) + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 1efd01e5d..6adb8c2e2 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -1315,4 +1315,25 @@ void ConfigFile::setDiscoveredLegacyConfigPath(const QString &discoveredLegacyCo _discoveredLegacyConfigPath = discoveredLegacyConfigPath; } +bool ConfigFile::hasRemotePollInterval(const QString &connection) const +{ + QString con(connection); + if (connection.isEmpty()) + con = defaultConnection(); + + QSettings settings(configFile(), QSettings::IniFormat); + settings.beginGroup(con); + + return settings.contains(QLatin1String(remotePollIntervalC)); +} + +void ConfigFile::resetRemotePollInterval(const QString &connection) { + QString con(connection); + if (connection.isEmpty()) + con = defaultConnection(); + + std::chrono::milliseconds defaultInterval(DEFAULT_REMOTE_POLL_INTERVAL); + setRemotePollInterval(defaultInterval, con); // Use existing method +} + } diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index f38fba1f1..bf6be3548 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -153,6 +153,8 @@ public: [[nodiscard]] bool useNewBigFolderSizeLimit() const; [[nodiscard]] bool confirmExternalStorage() const; void setConfirmExternalStorage(bool); + [[nodiscard]] bool hasRemotePollInterval(const QString &connection = QString()) const; + void resetRemotePollInterval(const QString &connection = QString()); /** If we should move the files deleted on the server in the trash */ [[nodiscard]] bool moveToTrash() const; -- 2.30.2